home *** CD-ROM | disk | FTP | other *** search
- /*----------------------------------------------------------------------------
-
- newart.c
-
- This module handles checking for new articles.
-
- Copyright © 1994-1995, Northwestern University.
-
- ----------------------------------------------------------------------------*/
-
- #include <string.h>
-
- #include "glob.h"
- #include "newart.h"
- #include "news.h"
- #include "mark.h"
- #include "newswatcher.h"
- #include "status.h"
- #include "memutil.h"
- #include "dialog.h"
- #include "listutil.h"
- #include "group.h"
-
-
-
- /*----------------------------------------------------------------------------
- DoCheckNewArticles
-
- Check to see if there are any new articles on the server for all of the
- groups in a user group list.
-
- Entry: wind = pointer to user group list window.
-
- Exit: function result = error code.
- ----------------------------------------------------------------------------*/
-
- OSErr DoCheckNewArticles(WindowPtr wind)
- {
- TWindow **info;
- ListHandle theList;
- TGroup **groupArray;
- short numGroups, numCells, cellDataLen, groupIndex;
- Cell theCell;
- TGroup theGroup;
- long numUnread;
- Boolean haveSelectedGroup;
- OSErr err = noErr;
-
- err = DisplayStatusMessageNumber(kStrChecking);
- if (err != noErr) return err;
-
- info = (TWindow**)GetWRefCon(wind);
- groupArray = (**info).groupArray;
- numGroups = (**info).numGroups;
- theList = (**info).theList;
- numCells = (**theList).dataBounds.bottom;
- theCell.h = 0;
-
- /* Close all child windows. */
-
- while ((**info).childList != nil) {
- err = DoClose((**(**info).childList).childWindow);
- if (err != noErr) return err;
- }
-
- /* Add [lastMess+1, maxlong] to the end of each group unread list.
- Mark each group in the list for an article range update. */
-
- for (theCell.v = 0; theCell.v < numCells; theCell.v++) {
- cellDataLen = 2;
- LGetCell(&groupIndex, &cellDataLen, theCell, theList);
- theGroup = (*groupArray)[groupIndex];
- numUnread = theGroup.numUnread;
- err = AppendUnreadRange(theGroup.lastMess+1, 0x7fffffff, &theGroup);
- if (err != noErr) return err;
- theGroup.numUnread = numUnread;
- theGroup.status = 'x';
- (*groupArray)[groupIndex] = theGroup;
- }
-
- /* Get new group article ranges from server. */
-
- err = GetGroupArrayArticleRanges(groupArray, numGroups);
-
- /* Adjust unread lists and redraw unread article counts. Select the first
- group with unread articles, if any. Note that we must do this even if
- we get an error from the call to GetGroupArrayArticleRanges above,
- because we have mucked with the unread lists in the group array, and
- we must put them back the way they were. */
-
- haveSelectedGroup = false;
- for (theCell.v = 0; theCell.v < numCells; theCell.v++) {
- cellDataLen = 2;
- LGetCell(&groupIndex, &cellDataLen, theCell, theList);
- theGroup = (*groupArray)[groupIndex];
- if (theGroup.status == 'x') {
- AdjustUnreadList(&theGroup);
- theGroup.onlyRedrawCount = true;
- (*groupArray)[groupIndex] = theGroup;
- LDraw(theCell, theList);
- (*groupArray)[groupIndex].onlyRedrawCount = false;
- if (haveSelectedGroup || theGroup.numUnread == 0) {
- MyLSetSelect(false, theCell, theList);
- } else {
- MyLSetSelect(true, theCell, theList);
- haveSelectedGroup = true;
- }
- } else {
- DisposeGroupUnreadList(&theGroup);
- theGroup.firstMess = 1;
- theGroup.lastMess = 0;
- theGroup.onlyRedrawCount = true;
- (*groupArray)[groupIndex] = theGroup;
- LDraw(theCell, theList);
- (*groupArray)[groupIndex].onlyRedrawCount = false;
- MyLSetSelect(false, theCell, theList);
- }
- }
- if (haveSelectedGroup) MyLAutoScroll(theList);
-
- /* Return the error code from the call to GetGroupArrayArticleRanges. */
-
- return err;
- }
-